const { db } = require('../config')
const { staff_collection } = require('../config')
const { workorder_collection } = require('../config')
exports.main = async (event, context) => {
    const data = event;
    const idsString = data.ids;
    const idsArr = idsString.split(",");
    let successCount = 0;
    for (let i = 0; i < idsArr.length; i++) {
        const res = await db.collection(workorder_collection).doc(idsArr[i]).update({
            status: '已删除'
        });
        woInfo = await db.collection(workorder_collection).doc(idsArr[i]).get();
        modifyStaff = JSON.parse(woInfo.data[0].modifyStaff);
        staffAccount = modifyStaff.account; //return [8888888, staffAccount]
        // 已离职员工恢复在职
        result = await db.collection(staff_collection).where({ account: staffAccount }).update({ status: "在职" });
        console.log("员工账号：" + staffAccount + "更新为在职");
        console.log(result, result.data);
        if (res.updated === 1) {
            successCount++;
        }
    }
    return { "successCount": successCount };
}